package com.zhengtoudai.ui.presenter;

import com.zhengtoudai.http.HttpApi;
import com.zhengtoudai.injector.PerActivity;
import com.zhengtoudai.ui.bean.Result;
import com.zhengtoudai.ui.view.CommonView;

import java.util.Map;

import javax.inject.Inject;

import rx.Subscriber;
import rx.Subscription;
import rx.functions.Action0;

/**
 * Created by Administrator on 2016/8/24 0024.
 */
@PerActivity
public class RegisterPresenterImpl extends BasePresenterImpl<CommonView> implements RegisterPresenter {

    @Inject
    public RegisterPresenterImpl() {

    }


    @Override
    public void register(Map<String, String> params) {
        Subscription registerSubscription=HttpApi.getInstance().register(params).doOnSubscribe(new Action0() {
            @Override
            public void call() {
                mView.showDialog();
            }
        }).subscribe(new Subscriber<Result>() {
            @Override
            public void onCompleted() {
                mView.dismissDialog();
            }

            @Override
            public void onError(Throwable e) {
                mView.onFailure(e);
                mView.dismissDialog();
            }

            @Override
            public void onNext(Result result) {
                mView.onResult(result);
            }
        });
       addSubscription(registerSubscription);
    }
}
